package com.api.shopapi.service.impl;


import com.api.shopapi.entity.AccountingRecord;
import com.api.shopapi.entity.Business;
import com.api.shopapi.entity.OrderBusiness;
import com.api.shopapi.entity.User;
import com.api.shopapi.entity.dto.OrderBusinessDTO;
import com.api.shopapi.entity.dto.OrderStatisticsDTO;
import com.api.shopapi.entity.dto.UserDTO2;
import com.api.shopapi.mapper.OrderBusinessMapper;
import com.api.shopapi.service.OrderBusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("OrderBusinessServiceImplOne")
public class OrderBusinessServiceImpl implements OrderBusinessService {

    @Autowired
    private OrderBusinessMapper orderBusinessMapper;

    @Override
    public int insert(OrderBusiness orderBusiness) {
        return orderBusinessMapper.insert(orderBusiness);
    }

    @Override
    public int delete(String orderBusinessCode) {
        return orderBusinessMapper.delete(orderBusinessCode);
    }

    @Override
    public int updateIsDelete() {
        return orderBusinessMapper.updateIsDelete();
    }

    @Override
    public int update(OrderBusiness orderBusiness) {
        return orderBusinessMapper.update(orderBusiness);
    }

    @Override
    public List<OrderBusiness> getList() {
        return orderBusinessMapper.getList();
    }

    @Override
    public OrderBusiness getByOrderBusinessCode(String orderBusinessCode) {
        return orderBusinessMapper.getByOrderBusinessCode(orderBusinessCode);
    }

    @Override
    public OrderBusiness getByOrderCode(String orderCode) {
        return orderBusinessMapper.getByOrderCode(orderCode);
    }

    @Override
    public List<OrderBusiness> getListByOrderCode(String orderCode) {
        return orderBusinessMapper.getListByOrderCode(orderCode);
    }



    //收银员的订单列表
    @Override
    public PageInfo<OrderBusinessDTO> getPageByUserCodeTable(int pageNum, int pageSize, String userCode){
        PageHelper.startPage(pageNum, pageSize);
        List<OrderBusinessDTO> list = orderBusinessMapper.getListByUserCodeTable(userCode);
        PageInfo<OrderBusinessDTO> pageInfo = new PageInfo<OrderBusinessDTO>(list);
        return pageInfo;
    }

    //收银员某时间段的订单列表
    @Override
    public
    List<OrderBusinessDTO> getListByUserCodeTableTime(String userCode, Date startTime, Date endTime){
        return orderBusinessMapper.getListByUserCodeTableTime(userCode,startTime,endTime);
    }


    @Override
    public PageInfo<OrderBusinessDTO> getPageInfoOrderBusinessDTOByUserCodeGovernmentCode(int pageNum,
                                                                                           int pageSize,
                                                                                           String userCode,
                                                                                           String governmentCode){
        PageHelper.startPage(pageNum, pageSize);
        List<OrderBusinessDTO> list = orderBusinessMapper.getListByUserCodeGovernmentCode(userCode,
                governmentCode);
        PageInfo<OrderBusinessDTO> pageInfo = new PageInfo<OrderBusinessDTO>(list);
        return pageInfo;
    }









    @Override
    public PageInfo<OrderBusinessDTO> getPageInfoOrderBusinessDTOByGovernmentCodeBusinessCode(int pageNum,
                                                                                              int pageSize,
                                                                                              String governmentCode,
                                                                                              String businessCode){
        PageHelper.startPage(pageNum, pageSize);
        List<OrderBusinessDTO> list = orderBusinessMapper.getListByGovernmentCodeBusinessCode(governmentCode,businessCode);
        PageInfo<OrderBusinessDTO> pageInfo = new PageInfo<OrderBusinessDTO>(list);
        return pageInfo;
    }









    //商家的所有订单
    @Override
    public List<OrderBusinessDTO> getListByBusinessCode(String businessTopCode){
        return orderBusinessMapper.getListByBusinessCode(businessTopCode);
    }
    @Override
    public PageInfo<OrderBusinessDTO> getPageInfoOrderBusinessDTOByBusinessCode(int pageNum, int pageSize,
                                                                                String businessTopCode){
        PageHelper.startPage(pageNum, pageSize);
        List<OrderBusinessDTO> list = orderBusinessMapper.getListByBusinessCode(businessTopCode);
        PageInfo<OrderBusinessDTO> pageInfo = new PageInfo<OrderBusinessDTO>(list);
        return pageInfo;
    }




    //商家的所有订单（增加状态，时间过滤）
    @Override
    public List<OrderBusinessDTO> getListByBusinessCodeStatusTime(String businessCode, int status,
                                                               Date beginTime,
                                                            Date endTime){
        return orderBusinessMapper.getListByBusinessCodeStatusTime(businessCode,status,beginTime,endTime);
    }
    @Override
    public PageInfo<OrderBusinessDTO> getPageInfoOrderBusinessDTOByBusinessCodeStatus(int pageNum, int pageSize,
                                                                               String businessCode,int status){
        PageHelper.startPage(pageNum, pageSize);
        List<OrderBusinessDTO> list = orderBusinessMapper.getListByBusinessCodeStatus(businessCode,status);
        PageInfo<OrderBusinessDTO> pageInfo = new PageInfo<OrderBusinessDTO>(list);
        return pageInfo;
    }







    //服务人员的订单（服务人员已绑定社区）
    @Override
    public PageInfo<OrderBusinessDTO> getPageInfoByServeCode(int pageNum, int pageSize, String userCode){
        PageHelper.startPage(pageNum, pageSize);
        List<OrderBusinessDTO> list = orderBusinessMapper.getListByServeCode(userCode);
        PageInfo<OrderBusinessDTO> pageInfo = new PageInfo<OrderBusinessDTO>(list);
        return pageInfo;
    }



    //服务人员某时间段的订单总数
    @Override
    public int getCountByBusinessCodeUserCode(String businessCode, String userCode, Date beginTime, Date endTime){
        return orderBusinessMapper.getCountByBusinessCodeUserCode(businessCode,userCode,beginTime,endTime);
    }

    //服务人员某时间段的订单总数（增加状态过滤）
    @Override
    public int getCountByBusinessCodeUserCodeStatus(String businessCode,
                                                    String userCode,
                                                    Date beginTime,
                                                    Date endTime,
                                                    int status){
        return orderBusinessMapper.getCountByBusinessCodeUserCodeStatus(businessCode,userCode,beginTime,endTime,status);
    }


    //所有订单（居委会，街道）
    @Override
    public List<OrderBusinessDTO> getListByZoneCode(String zoneCode){
        return orderBusinessMapper.getListByZoneCode(zoneCode);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getListForBusiness(int pageIndex, int pageSize, String businessCode, String governmentCode, Date beginTime, Date endTime, int status, int goodsType, String name, String phone) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getListForBusiness(businessCode, governmentCode, beginTime, endTime, status, goodsType, name, phone);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getListForWater(int pageIndex, int pageSize, String governmentCode, String businessCode, String name, String phone,Date beginTime,Date endTime) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getListForWater(governmentCode, businessCode, name, phone,beginTime,endTime);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getListForServe(int pageIndex, int pageSize, String userCode, Date beginTime, Date endTime,String name,String phone,int status) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList=orderBusinessMapper.getListForServe(userCode, beginTime, endTime,name,phone,status);
        return new PageInfo<>(orderBusinessDTOList);
    }


    //商家订单 服务类商品
    @Override
    public PageInfo<OrderBusinessDTO> getListForServiceOrder(int pageIndex, int pageSize, Date beginTime, Date endTime, String businessCode, String name, String phone, int status,int isDelete) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList=orderBusinessMapper.getListForServiceOrder(beginTime, endTime, businessCode, name, phone, status,isDelete);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public double getServeOrderBusinessPrice(Date beginTime, Date endTime, String businessCode, String name, String phone, int status, int isDelete) {
        return orderBusinessMapper.getServeOrderBusinessPrice(beginTime,endTime,businessCode,name,phone,status,isDelete);
    }


    //商家订单 服务类商品(管理员)
    @Override
    public PageInfo<OrderBusinessDTO> getListForServiceOrderAdm(int pageIndex, int pageSize, Date beginTime, Date endTime, String name, String phone, int status, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getListForServiceOrderAdm(beginTime, endTime, name, phone, status, governmentCode);
        return new PageInfo<>(orderBusinessDTOList);
    }


    @Override
    public PageInfo<OrderBusinessDTO> getListForCommonOrder(int pageIndex, int pageSize, Date beginTime, Date endTime, String businessCode, String name, String phone, int status,int isDelete) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getListForCommonOrder(beginTime, endTime, businessCode, name, phone, status,isDelete);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public double getCommonOrderBusinessPrice(Date beginTime, Date endTime, String businessCode, String name, String phone, int status, int isDelete) {
        return orderBusinessMapper.getCommonOrderBusinessPrice(beginTime,endTime,businessCode,name,phone,status,isDelete);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getListForCashierOrder(int pageIndex, int pageSize, Date beginTime, Date endTime, String businessCode, String name, String phone, int isDelete, String cashierCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getListForCashierOrder(beginTime, endTime, businessCode, name, phone, isDelete,cashierCode);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public double getCashierOrderBusinessPrice(Date beginTime, Date endTime, String businessCode, String name, String phone, int isDelete, String cashierCode) {
        return orderBusinessMapper.getCashierOrderBusinessPrice(beginTime,endTime,businessCode,name,phone,isDelete,cashierCode);
    }


    //商家订单 普通商品(管理员)
    @Override
    public PageInfo<OrderBusinessDTO> getListForCommonOrderAdm(int pageIndex, int pageSize, Date beginTime, Date endTime,  String name, String phone, int status, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getListForCommonOrderAdm(beginTime, endTime,  name, phone, status, governmentCode);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public List<OrderBusiness> getByStatus(int status) {
        return orderBusinessMapper.getByStatus(status);
    }

    @Override
    public List<OrderBusiness> getAutoCanceOrderByStatus() {
        return orderBusinessMapper.getAutoCanceOrderByStatus();
    }

    @Override
    public PageInfo<OrderBusinessDTO> getCommonOrderToGovPlatform(int pageIndex, int pageSize, Date startTime, Date endTime, String name, String phone, int status, String governmentCode, String businessCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getCommonOrderToGovPlatform(startTime, endTime,  name, phone, status, governmentCode,businessCode);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getServiceOrderToGovPlatform(int pageIndex, int pageSize, Date startTime, Date endTime, String name, String phone, int status, String governmentCode, String businessCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList =orderBusinessMapper.getServiceOrderToGovPlatform(startTime, endTime, name, phone, status, governmentCode,businessCode);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getForWaterForGov(int pageIndex, int pageSize, String startTime, String endTime,
                                                        String governmentCode,String name, String phone, int orderType,String businessCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList=orderBusinessMapper.getForWaterForGov(startTime, endTime,governmentCode, name, phone,businessCode,orderType);
        return new PageInfo<>(orderBusinessDTOList);
    }



    @Override
    public PageInfo<UserDTO2> getUserForConsumption(int pageIndex, int pageSize, Date startTime, Date endTime, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<UserDTO2> list =orderBusinessMapper.getUserForConsumption(startTime, endTime,governmentCode);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<OrderBusinessDTO> userConsumerOrderInfo(int pageIndex, int pageSize, String userCode, String startTime, String endTime, int orderType, String businessCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList = orderBusinessMapper.userConsumerOrderInfo(userCode, startTime, endTime, orderType, businessCode);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public List<OrderBusinessDTO> exportUserConsumerOrderInfo(String userCode, String startTime, String endTime, int orderType, String businessCode) {
        return orderBusinessMapper.userConsumerOrderInfo(userCode, startTime, endTime, orderType, businessCode);
    }

    @Override
    public PageInfo<OrderBusinessDTO> businessConsumerOrderInfo(int pageIndex, int pageSize, String startTime, String endTime, int orderType, String businessCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList = orderBusinessMapper.businessConsumerOrderInfo(startTime, endTime, orderType, businessCode);
        return new PageInfo<>(orderBusinessDTOList);
    }


    @Override
    public List<OrderBusiness> getOrderNowYearOrderNew(String governmentCode) {
        return orderBusinessMapper.getOrderNowYearOrderNew(governmentCode);
    }

    @Override
    public List<OrderBusiness> getOrderLastYearOrderNew(String governmentCode) {
        return orderBusinessMapper.getOrderLastYearOrderNew(governmentCode);
    }

    @Override
    public List<OrderBusiness> getOrderNowMonthsOrderNew(String governmentCode) {
        return orderBusinessMapper.getOrderNowMonthsOrderNew(governmentCode);
    }

    @Override
    public List<OrderBusiness> getOrderLastMonthsOrderNew(String governmentCode) {
        return orderBusinessMapper.getOrderLastMonthsOrderNew(governmentCode);
    }


    @Override
    public Double getMoneyNowYearMoney(String governmentCode) {
        return orderBusinessMapper.getMoneyNowYearMoney(governmentCode);
    }

    @Override
    public Double getMoneyLastYearMoney(String governmentCode) {
        return orderBusinessMapper.getMoneyLastYearMoney(governmentCode);
    }

    @Override
    public Double getMoneyNowMonthsMoney(String governmentCode) {
        return orderBusinessMapper.getMoneyNowMonthsMoney(governmentCode);
    }

    @Override
    public Double getMoneyLastMonthsMoney(String governmentCode) {
        return orderBusinessMapper.getMoneyLastMonthsMoney(governmentCode);
    }

    @Override
    public Double getBusinessNowYearMoney(String businessCode) {
        return orderBusinessMapper.getBusinessNowYearMoney(businessCode);
    }

    @Override
    public Double getBusinessDayMoney(String businessCode,int day) {
        return orderBusinessMapper.getBusinessDayMoney(businessCode,day);
    }

    @Override
    public PageInfo<OrderBusinessDTO> getBusinessDayList(int pageIndex,int pageSize,String businessCode, String dayTime, int orderType) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderBusinessDTO> orderBusinessDTOList = orderBusinessMapper.getBusinessDayList(businessCode,dayTime,orderType);
        return new PageInfo<>(orderBusinessDTOList);
    }

    @Override
    public int updateOrderBusinessStatus() {
        return orderBusinessMapper.updateOrderBusinessStatus();
    }

    @Override
    public int updateOrderBusinessTime() {
        return orderBusinessMapper.updateOrderBusinessTime();
    }

    @Override
    public List<AccountingRecord> getBusinessDayAllList() {
        return orderBusinessMapper.getBusinessDayAllList();
    }

    @Override
    public int getListStatis(String businessCode, String startTime, String endTime, String PayType) {
        int orderStatisticsPageInfo = orderBusinessMapper.getListStatis(startTime,endTime,businessCode,PayType);
        return orderStatisticsPageInfo;
    }

    @Override
    public PageInfo<OrderStatisticsDTO> getPayType(String startTime, String endTime,String businessCode, int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderStatisticsDTO> list = orderBusinessMapper.getPayType(startTime,endTime,businessCode);
        return new PageInfo<>(list);
    }

    @Override
    public double getListStatis2(String businessCode, String startTime, String endTime, String payType) {
        double orderStatisticsPageInfo = orderBusinessMapper.getListStatic(startTime,endTime,businessCode,payType);
        return orderStatisticsPageInfo;
    }


    //商家昨天的订单
    @Override
    public
    List<OrderBusiness> ListYesterday(String businessCode, Date startTime, Date endTime){
        return orderBusinessMapper.ListYesterday(businessCode,startTime,endTime);
    }


}
